Skip to content

fix: credential-env reads cred.encryptedKey (not cred.encrypted) - #95

Closed
siglimumuni wants to merge 1 commit into
swarmclawai:mainfrom
siglimumuni:fix/credential-env-field-name
Closed

fix: credential-env reads cred.encryptedKey (not cred.encrypted)#95
siglimumuni wants to merge 1 commit into
swarmclawai:mainfrom
siglimumuni:fix/credential-env-field-name

Conversation

@siglimumuni

Copy link
Copy Markdown
Contributor

Summary

Field-name mismatch in `buildCredentialEnv`. It reads `cred.encrypted` per-credential, but `createCredentialRecord` persists the ciphertext under `cred.encryptedKey`. Every call falls into the `Credential has no encrypted value` warn branch and returns an empty env map.

Result: every agent that uses `executeConfig.credentials` to inject API tokens has been getting an empty env. The execute tool's credential injection is a silent no-op today.

How I found it

Configured a fine-grained GitHub PAT as a credential on a worker agent, expecting `gh` inside its shell to authenticate via `$GITHUB_TOKEN`:

```
echo "GITHUB_TOKEN=${#GITHUB_TOKEN}chars"

→ GITHUB_TOKEN=0chars

```

`gh` then fell back to the host's keychain auth (much broader scope than the fine-grained PAT we tried to scope it to).

Why this is the fix

Every other read site in the codebase already uses `cred.encryptedKey`:

```
$ grep -rn 'cred.encryptedKey\|cred\.encrypted' src/ | grep -v .test.
src/lib/server/session-tools/credential-env.ts: cred.encrypted ← only consumer of the wrong field
src/app/api/setup/check-provider/route.ts: cred.encryptedKey
src/lib/server/connectors/connector-lifecycle.ts: cred.encryptedKey
src/lib/server/chatrooms/chatroom-helpers.ts: cred.encryptedKey
src/lib/server/runtime/daemon-state/core.ts: cred.encryptedKey
```

Verified

After the patch (applied locally to the running build):

```
echo "GITHUB_TOKEN=${#GITHUB_TOKEN}chars; first8=${GITHUB_TOKEN:0:8}"

→ GITHUB_TOKEN=93chars; first8=github_p

gh auth status

→ ✓ Logged in to github.com account siglimumuni (GITHUB_TOKEN)

```

Files

  • `src/lib/server/session-tools/credential-env.ts` — one-character field rename + a comment explaining the convention.

Test plan

  • Reviewed by inspection — single-line behavioral change.
  • Applied locally; runtime verified.

🤖 Generated with Claude Code

The execute tool's credential injection has been silently no-op'ing for
all agents: `buildCredentialEnv` read `cred.encrypted` on each Credential
record, but `createCredentialRecord` persists the ciphertext under
`encryptedKey` (confirmed by every other read site — connector-lifecycle,
chatroom-helpers, daemon-state, check-provider). The mismatch fell into
the `Credential has no encrypted value` warn branch on every call,
returning an empty env map. Agents using `executeConfig.credentials` to
inject API tokens into their shell environment never received them.

Concrete impact in our deployment: configured a fine-grained GitHub PAT
as a credential on Hugo + Iris, expecting `gh` inside the agent shell to
authenticate via `GITHUB_TOKEN`. The env var came through as empty, and
`gh` fell back to the host's keychain auth (much broader scope). Switching
the field name to `encryptedKey` makes the injection work as documented.

Confirmed by:
  - grep `cred.encrypted` across src/ — this file was the only consumer;
    every other site uses `cred.encryptedKey`.
  - Live test post-patch: `echo $GITHUB_TOKEN` inside an agent shell now
    returns the 93-char fine-grained PAT.

Files:
  - src/lib/server/session-tools/credential-env.ts
@waydelyle

Copy link
Copy Markdown
Member

Cherry-picked and shipped in v1.9.33 with maintainer follow-up coverage. Thanks for the fix.

@waydelyle waydelyle closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants